from webboard import models
from django import forms
from mdeditor.fields import MDTextFormField


class AddPostForm(forms.ModelForm):
    tags = forms.ModelMultipleChoiceField(
        queryset=models.Tag.objects.all(),
        widget=forms.CheckboxSelectMultiple,
        required=False,
        label="标签"
    )
    content = MDTextFormField(label="帖子内容")

    class Meta:
        model = models.Posts
        fields = ['title', 'tags', 'content']
        widgets = {
            'title': forms.TextInput(attrs={'class': "form-control", 'placeholder': '帖子标题'}),
        }

    # 如果需要在表单中初始化content字段，可以重写__init__方法
    def __init__(self, *args, **kwargs):
        super(AddPostForm, self).__init__(*args, **kwargs)
        # 你也可以在这里对widgets进行更多的定制


class RemarkForm(forms.ModelForm):
    class Meta:
        model = models.Remark
        fields = ['content']

        widgets = {
            "content": forms.TextInput(
                attrs={
                    'class': "w_input_container",
                    'maxlength': 200,
                    'style': 'resize: none; position:absolute; bottom:0; height:auto; top:100%; width:100%; box-sizing:border-box;'
                }
            ),
        }
